package com.bdqn.springweb.controller;

import com.bdqn.springweb.pojo.User;
import com.bdqn.springweb.service.Userservice;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Resource
    private Userservice UserService;

    /**
     * 登录
     */
    @RequestMapping("/login")
    public String login(String usrName, String usrPassword, Model model, HttpSession session){
        User User = UserService.login(usrName,usrPassword);
        if(User == null){
            model.addAttribute("message","用户名或密码错误，登录失败");
            return "forward:/login.jsp";
        }
        session.setAttribute("loginUser",User);
        return "redirect:/main";
    }

    /**
     * 进入到首页
     * @return
     */
    @RequestMapping("/main")
    public String main(){
        return "main";
    }
}
